<template>
  <div>
    <el-container id="container">
      <el-header>
        <div class="header-left">
          <span class="title" v-if="!isCollapse">
            佳陪陪护后台管理系统
          </span>
          <el-tooltip class="item" effect="dark" content="是否展开" placement="top-start">
            <i class="el-icon-s-unfold" @click="collapseHandle"></i>
          </el-tooltip>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="item.path" v-for="item in $route.matched" :key="item.path">
              {{ item.meta.title }}
            </el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <el-dropdown>
          <el-avatar shape="square" :size="50" src="https://p.qqan.com/up/2023-12/2023121483185903.jpg"></el-avatar>
          <span> {{ loginUser }}</span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>
              <span @click="doLogout">
                安全退出
              </span>
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside style="width:280px;overflow: hidden;" :class="{ active: isCollapse }">
          <AsideMenu :isCollapse="isCollapse"></AsideMenu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import AsideMenu from "@/components/AsideMenu.vue";
import { logout } from "@/api/auth";

export default {
  components: {
    AsideMenu: AsideMenu,
  },
  created() {
    let loginUser = JSON.parse(sessionStorage.getItem("loginUser"));
    this.loginUser = loginUser.userName
    console.log(this.$route.matched);
  },
  data() {
    return {
      loginUser: '',
      isCollapse: true // 是否折叠
    }
  },
  methods: {
    collapseHandle() {
      this.isCollapse = !this.isCollapse
    },
    doLogout() {
      logout().then((r) => {
        if (r.code == 200) {
          sessionStorage.removeItem("loginUser");
          this.$router.push("/Login");
        }
      });
    },
  },
};
</script>

<style scoped lang="less">
.el-tooltip {
  cursor: pointer;
}

.el-dropdown {
  display: flex !important;
  align-items: center;
  margin-right: 30px;
  padding: 0 20px;
  display: block;

  span {
    margin: 0 10px;
  }

  img {
    vertical-align: middle;
  }

  .el-dropdown-menu {
    padding: 0 30px;
  }
}

i {
  margin: 0 10px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.el-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #fcfcfc;
  box-shadow: 0 1px 4px rgba(0, 21, 41, .08);

  .header-left {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-breadcrumb {
      margin-left: 20px;
    }
  }
}

.active {
  width: 60px !important;
  height: 100vh;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  overflow: hidden;
  transition: all .2s;
}
</style>
